**********************************************************************************************
* Reproduces Figures A.7
*
* Cloyne, Dimsdale and Hürtgen (2024) 								
*	"Are Tax Cuts Contractionary at the Zero Lower Bound? Evidence from a Century of Data"  	  		
*																			
* James Cloyne, Nicholas Dimsdale and Patrick Hürtgen, 2024
**********************************************************************************************

global outputfolder = "${rootfolder}/StateDep"
capture mkdir ${outputfolder}
global outputfolder = "${outputfolder}/${figure}"
capture mkdir ${outputfolder}

* control set specification
capture macro drop controlist 
capture macro drop controlist1 controlist2


*---------------------------------------------------------*
*-------------------- Setup --------------------*
*---------------------------------------------------------*

global approach = "LP"
global LHS = "smoothed"

* Sample harmonization
global harmonized = 0


* ---------- LP regression --------------- *
global qLags = 4  // lags for Tax shocks
global pLags = 4  // lags for controls
global gLags = 0  // lags for government spending shock controls
global hmax = ${hmax}

global controlist lnRealGDP lnRealTaxRev lnRealExp BankRate 		


/* -------------  Baseline LP ------------ */

use ${datapath}/${DataSetName},clear

forv pair = 1/2 {
	
	if `pair' == 1 {
		global Unanticipated = 1
		global noITC = 0
		global shockversion = "LRConsistent"
		global shocksheet = "baseline"
		}
	else if `pair' == 2 {
		global Unanticipated = 0
		global noITC = 0
		global shockversion = "LRConsistent"
		global shocksheet = "baseline"
	}
	
	do ${dofilepath}/MacroData_${shockversion}Shocks.do
	
	foreach y in lnRealGDP {
	
	preserve 
	global depvar = "`y'"

	do ${dofilepath}/LP_DataTransform_LR.do

	local labely : variable label $depvar
	local yname = subinstr("`labely'"," ","",.)
	local filename = "S_`yname'ToTax_${LHS}" 

	if $skipsample == 1 {
		local filename = "`filename'_s"  
	}
	
	log close _all 

	log using ${outputfolder}/`filename', name(StateDep_ZLB_${depvar}) text replace

	do ${dofilepath}/LP_IRFs_StateDep.do
	
	if $PlotIRF == 1 & $saveFigs == 1 {

		forv j = 0/1 {
			gr export "${outputfolder}/IRF_`filename'_Regime`j'_Pair`pair'.pdf", name(IRF_`yname'_`j') replace
			
		}
	}
	
	keep Quarters b0 b1 u${alpha2}* d${alpha2}* u${alpha1}* d${alpha1}*
	drop if Quarters == .
	
	ren b0 point_NoZLB
	ren b1 point_ZLB
	ren u${alpha2}0 u${alpha2}_NoZLB
	ren u${alpha2}1 u${alpha2}_ZLB
	ren u${alpha1}0 u${alpha1}_NoZLB
	ren u${alpha1}1 u${alpha1}_ZLB
	ren d${alpha2}0 d${alpha2}_NoZLB
	ren d${alpha2}1 d${alpha2}_ZLB
	ren d${alpha1}0 d${alpha1}_NoZLB
	ren d${alpha1}1 d${alpha1}_ZLB
	
	save "${outputfolder}/DataIRF_`filename'_`y'_${LHS}_Pair`pair'.dta", replace
	export excel "${outputfolder}/DataIRF_`filename'_`y'_${LHS}_Pair`pair'.xlsx", firstrow(variables)  keepcellfmt replace

	log close _all
	
	restore
	}
	
}


forv pair = 1/2 {
	
	if `pair' == 1 {
		*global version = "v21"
		global Unanticipated = 1
		global noITC = 0
		global shockversion = "LRConsistent"
		global shocksheet = "baseline"
		}
	else if `pair' == 2 {
		*global version = "v21"
		global Unanticipated = 0
		global noITC = 0
		global shockversion = "LRConsistent"
		global shocksheet = "baseline"
	}
	
	do ${dofilepath}/MacroData_${shockversion}Shocks.do

	foreach y in lnRealGDP  {


	global outputfolder = "${rootfolder}/AE"
	capture mkdir ${outputfolder}
	global outputfolder = "${outputfolder}/${figure}"
	capture mkdir ${outputfolder}

	preserve
	
	global depvar = "`y'"

	local labely : variable label $depvar
	local yname = subinstr("`labely'"," ","",.)

	do ${dofilepath}/LP_DataTransform_LR.do

	local labely : variable label $depvar
	local yname = subinstr("`labely'"," ","",.)

	log close _all

	local filename = "AE_`yname'ToTax_${LHS}" 

	if "${shockversion}" == "LRConsistent" {

		if $skipsample == 1 {
			local filename = "`filename'_s" 
		}
	}

	log using ${outputfolder}/`filename', name(${approach}_${LHS}) text replace

	do ${dofilepath}/LP_IRFs.do

	if $PlotIRF == 1 & $saveFigs == 1 {
		gr export "${outputfolder}/IRF_`filename'_Pair`pair'.pdf", replace
	}

	list Quarters b u* d*   if !missing(Quarters)
	
	keep Quarters b u${alpha2}* d${alpha2}* u${alpha1}* d${alpha1}*
	drop if Quarters == .
	
	save "${outputfolder}/DataIRF_`filename'_${LHS}_Pair`pair'.dta", replace
	export excel "${outputfolder}/DataIRF_`filename'_${LHS}_Pair`pair'.xlsx", firstrow(variables)  keepcellfmt replace


	log close _all
	
	restore
		
	}

}

global Unanticipated = 0
global noITC = 0

do ${dofilepath}/MacroData_${shockversion}Shocks.do

		



